package com.qf.sy2103.fmmall.api.controller;

import com.qf.sy2103.common.utils.JwtUtils;
import com.qf.sy2103.common.vo.ResStatus;
import com.qf.sy2103.common.vo.ResultVO;
import com.qf.sy2103.fmmall.beans.entity.Users;
import com.qf.sy2103.fmmall.beans.vo.UserRegistVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/user")
@Api(value = "提供用户的登录和注册接口",tags = "用户管理")
public class UserController {

    @ApiOperation("用户登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string",name = "username", value = "用户登录账号",required = true),
            @ApiImplicitParam(dataType = "string",name = "password", value = "用户登录密码",required = true)
    })
    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public ResultVO login( String username,String password ){

        final ResultVO resultVO = new ResultVO();

        resultVO.setCode(ResStatus.OK);
        // 生产jwt token
        final String token = JwtUtils.createToken(username, "100");
        resultVO.setMsg(token);
        final Users users = new Users();
        users.setUserId(1);
        users.setUsername("zhangsan");
        users.setUserImg("img/default.png");
        resultVO.setData(users);

        return resultVO;
    }

    @RequestMapping(value = "/regist",method = RequestMethod.POST)
    public ResultVO regist(@RequestBody UserRegistVo userRegistVo ){
        System.out.println(userRegistVo);

        final ResultVO resultVO = new ResultVO();

        resultVO.setCode(ResStatus.OK);
        resultVO.setMsg("success");resultVO.setData(new Users());

        return resultVO;
    }

}
